package com.nervenets.shopping.controller.role.dto;

import com.nervenets.shopping.hibernate.domain.user.RoleGroup;
import com.nervenets.shopping.service.ManagerService;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.util.List;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class RoleModel implements Serializable {
    @ApiModelProperty(value = "ID")
    private long id;
    @ApiModelProperty(value = "名称")
    private String name;
    @ApiModelProperty(value = "描述")
    private String detail;
    @ApiModelProperty(value = "功能数量")
    private int roleCount;
    @ApiModelProperty(value = "成员数量")
    private long member;
    @ApiModelProperty(value = "是否启用")
    private boolean enable;
    @ApiModelProperty(value = "子权限")
    private List<RoleModel> children;

    public RoleModel(RoleGroup roleGroup, ManagerService managerService) {
        this.id = roleGroup.getId();
        this.name = roleGroup.getName();
        this.detail = roleGroup.getDetail();
        this.roleCount = roleGroup.getRoles().size();
        this.member = managerService.countByRoleGroupsId(roleGroup);
        this.enable = roleGroup.isEnable();
    }
}
